package com.android.smartdial;

import java.util.ArrayList;
import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class SmartDial extends Activity implements View.OnClickListener{
	//Button btn;
	
	/** Called when the activity is first created. */
    @Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		
		/*
		btn = new Button(this);
		btn.setOnClickListener(this);
		updateTime();
		*/
		
		//setContentView(btn);
		
		setContentView(R.layout.main);
		
		ListView myListView = (ListView)findViewById(R.id.myListView);
		final EditText myEditText = (EditText)findViewById(R.id.myEditText);
		
		final ArrayList<String> todoItems = new ArrayList<String>();
		final ArrayAdapter<String> aa;
		aa = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1,
				todoItems);
		myListView.setAdapter(aa);
		
		myEditText.setOnKeyListener(new OnKeyListener() {
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (event.getAction() == KeyEvent.ACTION_DOWN) {
					if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
						todoItems.add(0, myEditText.getText().toString());
						aa.notifyDataSetChanged();
						myEditText.setText("");
						return true;
					}
				}
				return false;
			}
		});
		
	}
    
    public void onClick(View view) {
    	updateTime();
    }
    
    
    private void updateTime() {
    	//btn.setText(new Date().toString());
    }
}
